package org.jackysoft.entity;

import java.util.Collection;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Transient;

import org.apache.struts2.json.annotations.JSON;
import org.jackysoft.entity.Department;
import org.jackysoft.entity.User;
import org.joda.time.DateTime;

import com.google.common.collect.Lists;

/**
 * 成品月报表
 * */
@Entity
@org.hibernate.annotations.Entity(dynamicUpdate = true, dynamicInsert = true)
public class ArmMonthlyFinishedProductReporter extends AbstractReporter {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7397110978420137276L;
	private ArmMonthlyFinishedProductReporter last;
	private Collection<ArmItem> lastItems     = Lists.newArrayList();
	private Collection<ResearchArmItem> researchItems = Lists.newArrayList();
	
	
	public ArmMonthlyFinishedProductReporter() {
		super();
	}

	public ArmMonthlyFinishedProductReporter(String id, String title,
			DateTime createDate,
			DateTime updateDate, User maker, Department department) {
		super(id, title,createDate,updateDate, maker, department);		
	}

	public void setLast(ArmMonthlyFinishedProductReporter last) {
		this.last = last;
	}

	@ManyToOne
	public ArmMonthlyFinishedProductReporter getLast() {
		return last;
	}

	@Transient
	public Collection<ArmItem> getLastItems() {
		return lastItems;
	}

	public void setLastItems(Collection<ArmItem> lastItems) {
		this.lastItems = lastItems;
	}
		
	@OneToMany(targetEntity = ResearchArmItem.class,orphanRemoval=true,cascade=CascadeType.ALL)
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.ALL})
	@JoinTable(
			name="arm_finished_research_item",
			joinColumns = { @JoinColumn(name = "reporter_id")}, 
			inverseJoinColumns = @JoinColumn(name = "research_armitem_id")		
	)
	@JSON(serialize=false)	
	public Collection<ResearchArmItem> getResearchItems() {
		return researchItems;
	}

	public void setResearchItems(Collection<ResearchArmItem> researchItems) {
		this.researchItems = researchItems;
	}
		

}
